/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.ruchin.tek.employees.web;

import com.google.gson.Gson;
import javax.servlet.ServletContext;
import ru.ruchin.tek.employees.data.Department;
import ru.ruchin.tek.employees.data.EmployeeStorage;
import ru.ruchin.tek.employees.json.GsonUtils;

/**
 *
 * @author yruchin
 */
class EmployeeListQueryHandler implements QueryHandler {
    @Override
    public String handleQuery(java.util.Map<String, String[]> query, ServletContext context) {
        Gson g = GsonUtils.getSharedGson();
        
        EmployeeStorage es = (EmployeeStorage)context.getAttribute(EmployeeStorage.CONTEXT_KEY);
        Department d = es.getDepartmentById(Long.parseLong(query.get("id")[0]));
        
        return g.toJson(d.getEmployees());
    }
}
